﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using Models.WebSite_HaiSheng;
using System.Configuration;
namespace Utilities
{
    
    public class DB : DbContext
    {
        public DbSet<Article> Articles { get; set; }
        public DbSet<Message> Messages { get; set; }
        public DbSet<Case> Cases { get; set; }
        public DbSet<Company> Companies { get; set; }
        public DbSet<CompanyType> CompanyTypes { get; set; }
        public DbSet<Image> Images { get; set; }
        public DbSet<ImageRelateTo> ImageRelateTos { get; set; }
        public DbSet<Front> Fronts { get; set; }
        public DbSet<Recruitment> Recruitments { get; set; }
        public DbSet<JobApply> JobApplys { get; set; }
        public DbSet<FileDownload> FileDownloads { get; set; }
        public DbSet<ChildCompany> ChildCompanys { get; set; }
        public DbSet<EmployeeReward> EmployeeRewards { get; set; }
        public DB()
        {

            if (AppConfig.ConnectionStringSetting == "release")
            {
                Database.SetInitializer<DB>(null);
            }
            else if (AppConfig.ConnectionStringSetting == "develop")
            {
                Database.SetInitializer<DB>(new DropCreateDatabaseIfModelChanges<DB>());
            }
            this.Configuration.ValidateOnSaveEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //this.Configuration.LazyLoadingEnabled = false;
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }  
    }

    public class ProcessInitializer : DropCreateDatabaseIfModelChanges<DB>
    {
        protected override void Seed(DB context)
        {
            #region fake data
            FakeData(context);
            
            #endregion
        }

        private void FakeData(DB context)
        {
        }
    }
}